home *** CD-ROM | disk | FTP | other *** search
- Path: pegasus.montclair.edu!harmon
- From: harmon@pegasus.montclair.edu (Derek Harmon)
- Newsgroups: comp.lang.c
- Subject: Re: gets(rec->num); I don't know what I am doing wrong...
- Date: 9 Feb 1996 03:36:20 -0500
- Organization: Montclair State University
- Message-ID: <harmon.823853493@pegasus.montclair.edu>
- References: <4fempt$mjg@aphex.direct.ca>
- NNTP-Posting-Host: pegasus.montclair.edu
- X-Newsreader: NN version 6.5.0 #68 (NOV)
-
- etoivane@direct.ca (Ed Toivanen) writes:
-
- >I posted the code that I wrote so far. I can't make gets(rec->id); work
- >properly, I get 6 or 7 compilation errors indicating that parameter 1 does not
- >match function prototype. Each gets() call is incorrect! What to do?
-
- Ok, straight out I'd say gets(rec->id) will fail because id (as defined
- in your code) is an integer. gets() is typical C terse wording for "get string"
- so when you see gets(), think "get string." rec->id is not a string. The
- most direct solution is:
-
- : char temp[16]; /* temporary buffer to hold string to be gotten */
- :
- : gets(temp);
- : rec->id = atoi(temp); /* convert string to integer value */
- : /* no error checking is performed. */
-
- >typedef struct science_mark {
- > int math, physics, compsci; /* Range: 0..100 */
- >}SCIENCE_MARK;
-
- Notice that these values are integers. Now if we look at your switch
- statement here:
-
- > case SCIENCE:
- > printf("Math\n");
- > fprintf(fp, gets(rec->marks.scientist.math));
-
- We see that you are using gets() to read in one of these integers. gets()
- is strictly for character strings, and you'll have to implement the snippet
- above most of the places where gets() has generated a compilation error for
- you. You'll only need one temp buffer, since the input string is discardable
- after you've converted it to an integer.
-
- Incidentally, not ALL of your gets() should have caused problems. For
- example:
-
- > printf("Student's last name first\n");
- > gets(rec->name);
-
- Should have compiled easily. :) You just need to apply the above handling
- for inputting integer values.
- -- Stone
- --
- # Derek Harmon (aka Stonelight) harmon@pegasus.montclair.edu
- # - Computer Science Undergrad, Montclair State University, NJ
- # - My views are my own, nobody else is this creative. 3;)>
- ... No program is so formidable that you can't just delete it.
-